package cn.tedu.egmvc.controller;

import cn.tedu.egmvc.mapper.AddressMapper;
import cn.tedu.egmvc.pojo.dto.AddressDTO;
import cn.tedu.egmvc.pojo.retity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @RequestMapping("/address/insert")
    public String inset(AddressDTO addressDTO){
        System.out.println(addressDTO);
        Address address=new Address();
        BeanUtils.copyProperties(addressDTO,address);
        int num=addressMapper.insert(address);
        return num>0?"添加成功":"添加失败";
    }
    @RequestMapping("/address/delete")
    public String delete(Integer id){
        int num=addressMapper.delete(id);
        return num>0?"删除成功":"删除失败";
    }
    @RequestMapping("/address/update")
    public String update(AddressDTO addressDTO,Integer id){
        Address address=new Address();
        BeanUtils.copyProperties(addressDTO,address);
        address.setId(id);
        int num=addressMapper.update(address);
        return num>0?"更新成功":"更新失败";
    }
    @RequestMapping("/address/select")
    public List<Address> select(){
        return addressMapper.select();
    }
}
